﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Reflection;

namespace Cms.Web.CmsSystem.SysAdmin.FormSetting
{
    public partial class DrawForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public string GetControlDefaultAttribute()
        {
            Type basetype = typeof(BLL.Controls.BaseControl);
            Assembly[] asslist = AppDomain.CurrentDomain.GetAssemblies();
            Assembly assembly = Assembly.Load("Cms.BLL");
            Dictionary<string, object> dict = new Dictionary<string, object>();
            if (assembly != null)
            {
                Type[] types = assembly.GetTypes();
                foreach (Type type in types)
                {
                    bool ischild = IsParent(type, basetype);
                    if (ischild)
                    {
                        object obj = Activator.CreateInstance(type);
                        dict.Add(type.Name.ToLower(), obj);
                    }
                }
            }
            return EntLib.Json.ToJson(dict);
        }
        public static bool IsParent(Type test, Type parent)
        {
            if (test == null || parent == null || test == parent || test.BaseType == null)
            {
                return false;
            }
            if (parent.IsInterface)
            {
                foreach (var t in test.GetInterfaces())
                {
                    if (t == parent)
                    {
                        return true;
                    }
                }
            }
            else
            {
                do
                {
                    if (test.BaseType == parent)
                    {
                        return true;
                    }
                    test = test.BaseType;
                } while (test != null);

            }
            return false;
        }

    }
}